home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 70 / IOPROG_70.ISO / soft / Codice / Libro Allegato / EsempiLibroVBA.bas next >
Encoding:
BASIC Source File  |  2003-05-02  |  6.4 KB  |  228 lines

  1. Attribute VB_Name = "EsempiLibroVBA"
  2. Option Explicit
  3.  
  4.  
  5. Sub sommaByRef(ByRef a)
  6.  a = a + 1
  7. End Sub
  8.  
  9. Sub sommaByVal(ByVal a)
  10.  a = a + 1
  11. End Sub
  12.  
  13. Sub sommaDefault(a)
  14.  a = a + 1
  15. End Sub
  16.  
  17. Function funSommaDefault(paramA)
  18.     paramA = paramA + 1
  19.     funSommaDefault = paramA
  20. End Function
  21.  
  22.  
  23. Sub test()
  24.     Dim a As Integer
  25.     a = 1
  26.     MsgBox "Valore iniziale: " & a
  27.     sommaDefault a
  28.     MsgBox "Dopo 'sommaDefault a' : " & a
  29.     sommaDefault (a)
  30.     MsgBox "Dopo 'sommaDefault (a)' : " & a
  31.     Call sommaDefault(a)
  32.     MsgBox "Dopo 'Call sommaDefault(a)' : " & a
  33.     a = 1
  34.     MsgBox "Valore iniziale: " & a
  35.     sommaByRef a
  36.     MsgBox "Dopo 'sommaByRef a' : " & a
  37.     sommaByRef (a)
  38.     MsgBox "Dopo 'sommaByRef (a) :' " & a
  39.     Call sommaByRef(a)
  40.     MsgBox "Dopo 'Call sommaByRef(a) :' " & a
  41.     a = 1
  42.     MsgBox "Valore iniziale: " & a
  43.     sommaByVal a
  44.     MsgBox "Dopo 'sommaByVal a' : " & a
  45.     sommaByVal (a)
  46.     MsgBox "Dopo 'sommaByVal (a)' : " & a
  47.     Call sommaByVal(a)
  48.     MsgBox "Dopo 'Call Call sommaByVal(a)' : " & a
  49. End Sub
  50.  
  51.  
  52. Sub testFun()
  53.     Dim a As Integer
  54.     a = 1
  55.     MsgBox "Valore iniziale: " & a
  56.     MsgBox "'funSommaDefault(a)' ritorna : " & funSommaDefault(a)
  57.     MsgBox "Ora 'a' vale : " & a
  58.     funSommaDefault a
  59.     MsgBox "applicato 'funSommaDefault a'; ora 'a' vale : " & a
  60. End Sub
  61.  
  62.  
  63. Sub testmsg()
  64. Dim variab
  65. variab = MsgBox("Testo", vbExclamation + vbYesNo)
  66. End Sub
  67.  
  68.  
  69. Sub dimmiComposizione()
  70.     MsgBox "Application.ActiveWorkbook.Name = " & _
  71.         Application.ActiveWorkbook.Name
  72.     MsgBox "Application.Worksheets.Count = " & _
  73.         Application.Worksheets.Count
  74.     MsgBox "Application.Worksheets.Item(1).Name = " & _
  75.         Application.Worksheets.Item(1).Name
  76.     MsgBox "Application.Worksheets.Item(""Foglio1"").Name = " & _
  77.         Application.Worksheets.Item("Foglio1").Name
  78.     Dim elem As Worksheet
  79.     
  80.     For Each elem In Application.Worksheets
  81.         MsgBox "(insieme Worksheets) elem.Name = " & elem.Name
  82.     Next
  83.     MsgBox "Application.Charts.Count = " & Application.Charts.Count
  84.     For Each elem In Application.Charts
  85.         MsgBox "(insieme Charts) elem.Name = " & elem.Name
  86.     Next
  87.     For Each elem In Application.Sheets
  88.         MsgBox "(insieme Sheets) elem.Name = " & elem.Name
  89.     Next
  90.     
  91.     
  92. End Sub
  93.  
  94.  
  95.  
  96. Sub provaRange()
  97.     colora Range("A1"), 1
  98.     colora Range("B17:B20"), 3
  99.     colora Range("A3:F9"), 7
  100.     colora Range("D:D"), 4
  101.     colora Range("H:H,J:J"), 8
  102.     colora Range("11:11,13:15"), 6
  103. End Sub
  104.  
  105. Sub colora(cosa As Range, colore As Integer)
  106.     cosa.Interior.ColorIndex = colore
  107.     cosa.Value = colore
  108. End Sub
  109.  
  110. Sub coloraOffset(originale As Range, OffsetX As Integer, OffsetY As Integer, colore As Integer)
  111.     colora originale, colore
  112.     colora originale.Offset(OffsetX, OffsetY), colore
  113. End Sub
  114.  
  115. Sub provaOffset()
  116.     coloraOffset Range("A1"), 2, 3, 7
  117.     coloraOffset Range("C7"), -2, 3, 3
  118.     coloraOffset Range("F18"), 2, -3, 4
  119.     coloraOffset Range("K11"), -2, -3, 6
  120. End Sub
  121.  
  122. Sub provaOffsetGruppi()
  123.     coloraOffset Range("A1:B4"), 6, 1, 7
  124.     coloraOffset Range("F16,G20"), -2, -4, 6
  125.     coloraOffset Range("I:I"), 0, 2, 8
  126. End Sub
  127.  
  128. Sub creaDocumentoWord()
  129.     Dim wdApp As New Word.Application
  130.     Dim wdDoc As Word.Document
  131.     Dim wdTable As Word.Table
  132.     Dim wdRow As Word.Row
  133.     
  134.     Dim cella As Excel.Range
  135.     
  136.     wdApp.Visible = True
  137.     Set wdDoc = wdApp.Documents.Add(, , , True)
  138.     Set wdTable = wdDoc.Tables.Add(wdDoc.Range(), 1, 2)
  139.     wdTable.Rows.Item(1).Alignment = wdAlignRowCenter
  140.     wdTable.Cell(1, 1).Range.Characters.Item(1) = "Cella"
  141.     wdTable.Cell(1, 2).Range.Characters.Item(1) = "Valore"
  142.     For Each cella In ActiveWorkbook.ActiveSheet.UsedRange
  143.         Set wdRow = wdTable.Rows.Add()
  144.         wdRow.Cells(1).Range.Characters.Item(1) = cella.Address
  145.         wdRow.Cells(2).Range.Characters.Item(1) = cella.Characters.Text
  146.     Next
  147.     wdApp.Quit
  148.     Set wdApp = Nothing
  149. End Sub
  150.  
  151. Sub creaPresentazionePowerPoint()
  152.     Dim app As New PowerPoint.Application
  153.     Dim nuovaPresentazione As PowerPoint.Presentation
  154.     Dim nuovaSlide As PowerPoint.Slide
  155.     Dim indiceSlide As Integer
  156.     indiceSlide = 1
  157.     app.Visible = msoTrue
  158.     Set nuovaPresentazione = app.Presentations.Add
  159.     Set nuovaSlide = _
  160.         nuovaPresentazione.Slides.Add(indiceSlide, ppLayoutText)
  161.     nuovaSlide.Shapes.Item(1).TextFrame.TextRange.Text = "Titolo"
  162.     nuovaSlide.Shapes.Item(2).TextFrame.TextRange.Text = "Testo inserito"
  163.     indiceSlide = indiceSlide + 1
  164.     Set nuovaSlide = _
  165.         nuovaPresentazione.Slides.Add(indiceSlide, ppLayoutVerticalText)
  166.     nuovaSlide.Shapes.Item(1).TextFrame.TextRange.Text = "Titolo"
  167.     nuovaSlide.Shapes.Item(2).TextFrame.TextRange.Text = "Testo inserito"
  168.     indiceSlide = indiceSlide + 1
  169.     Set nuovaSlide = _
  170.         nuovaPresentazione.Slides.Add(indiceSlide, ppLayoutOrgchart)
  171.     indiceSlide = indiceSlide + 1
  172.     Set nuovaSlide = _
  173.         nuovaPresentazione.Slides.Add(indiceSlide, ppLayoutTextAndChart)
  174.     indiceSlide = indiceSlide + 1
  175.     Set nuovaSlide = _
  176.         nuovaPresentazione.Slides.Add(indiceSlide, ppLayoutChartAndText)
  177.         
  178.     indiceSlide = indiceSlide + 1
  179.     Set nuovaSlide = _
  180.         nuovaPresentazione.Slides.Add(indiceSlide, ppLayoutClipartAndText)
  181.         
  182.     indiceSlide = indiceSlide + 1
  183.     Set nuovaSlide = _
  184.         nuovaPresentazione.Slides.Add(indiceSlide, ppLayoutMediaClipAndText)
  185.             
  186. End Sub
  187.  
  188.  
  189. Sub creaEmailOutlook()
  190.     Dim applic As Outlook.Application
  191.     Dim messaggio As Outlook.MailItem
  192.     Set applic = New Outlook.Application
  193.     Set messaggio = applic.CreateItem(olMailItem)
  194.     messaggio.Body = "Corpo"
  195.     messaggio.Subject = "Soggetto"
  196.     messaggio.Recipients.Add "i_venuti@yahoo.it"
  197.     messaggio.CC = "mlizza@humnet.unipi.it"
  198.     messaggio.Display
  199. End Sub
  200.  
  201. Sub testaFS()
  202.     testaFileSearch "Z:\Ivan"
  203. End Sub
  204.  
  205. Sub testaFileSearch(path As String)
  206.     Dim lista As String
  207.     Dim i As Integer
  208.     
  209.     lista = ""
  210.     With Application.FileSearch
  211.         .NewSearch
  212.         .Filename = "m*"
  213.         .FileType = msoFileTypeOfficeFiles
  214.         .LookIn = path
  215.         .SearchSubFolders = True
  216.         .Execute
  217.         For i = 1 To .FoundFiles.Count
  218.             lista = lista & VBA.vbCrLf & VBA.vbTab & .FoundFiles(i)
  219.         Next i
  220.     End With
  221.     MsgBox "File che soddisfano i criteri di ricerca:" & lista
  222. End Sub
  223.  
  224.  
  225.  
  226.  
  227.  
  228.